<template>
    <div class="view3Receipt">
        <!-- <div class="header">
            <x-icon type="ios-arrow-left" size="" class="icon-white" @click="$router.go(-1)"></x-icon>{{$route.query.name}}
        </div> -->
        <div class="view3ReceiptBox">
            <h2>
                <span>共计: {{total}} 条</span>
                <em>已选择: {{num}} 条</em>
            </h2>
            <div class="standard-wrap">
                <div v-for="(item,index) in  listArr2"
                     v-bind:key="index"
                     class="item-wrap">
                    <standardItem :item="item"
                                  :showChild="showChild"
                                  :selectStandard="selectStandard"></standardItem>
                </div>
            </div>
            <h4 class="btn">
                <div @click="btn">完成</div>
            </h4>
        </div>
        <myMenu @clickBack="back"></myMenu>
    </div>
</template>
<script>
import { Group, CellBox, Checklist, Cell } from 'vux'
import myMenu from '@/commonComponents/menu'
import standardItem from './select'
export default {
    components: {
        Group,
        Checklist,
        Cell,
        CellBox,
        standardItem,
        myMenu
    },
    data () {
        return {
            show_p: false,
            demo1: false,
            commonList: ['来测试下这个长度问题,你都想不到这个会是个BUg', 'Japan', 'America'],
            labelPosition: '',
            checklist001: [],
            showContent001: false,
            listArr2: [],
            param2: {
                allowPaging: true,
                business: 'GetCheckWorkHiddenDangers',
                data: {
                    CategoryId: '',
                    id: ''
                },
                pageIndex: 0,
                pageSize: 1000,
                tokenId: 'D0853C0CE5A6A478F5C613B840394FC3',
                userId: '615123137'
            },
            total: 0,
            num: 0,
            HiddenDangerIds: '',
            HiddenDangers: []
        }
    },
    created () {
        this.param2.data.id = this.$route.query.id
        var token = JSON.parse(window.localStorage.getItem('userInfo'))
        this.param2.userId = token.userid
        // console.log(this.$store.state.HiddenDangers)
        this.HiddenDangers = this.$store.state.HiddenDangers
        console.log(this.HiddenDangers)
        this.dataArr()
    },
    methods: {
        back () {

        },
        showChild (deptId, item) {
            item.open = !item.open
        },
        selectStandard (item) {
            item.checked = !item.checked
            var arr = this.listArr2
            var parmas = ''
            for (var k of arr) {
                for (var j of k.problemSummaries) {
                    if (j.checked) {
                        parmas += j.Id + '_'
                    }
                }
            }
            parmas = parmas.substr(0, parmas.length - 1)
            this.HiddenDangerIds = parmas
            this.num = this.HiddenDangerIds.split('_').length
        },
        // 页面数据
        dataArr () {
            this.$axiosAjax.getConfigJson(this.param2).then((res) => {
                if (res.status) {
                    var arr = res.data.data
                    var a = []
                    for (var k of arr) {
                        for (var j of k.problemSummaries) {
                            a.push(j.No)
                            j.checked = false
                        }
                        k.open = false
                    }
                    this.listArr2 = arr
                    for (let i = 0; i < this.HiddenDangers.length; i++) {
                        if (this.HiddenDangers[i].state === '已填写') {
                            let hasType = false
                            for (let j = 0; j < this.listArr2.length; j++) {
                                if (this.HiddenDangers[i].category == this.listArr2[j].checkTitleNames) {
                                    this.listArr2[j].checkProblemNums++
                                    this.listArr2[j].problemSummaries.push({
                                        Description: this.HiddenDangers[i].description,
                                        HdLevel: this.HiddenDangers[i].hdLevel ? this.HiddenDangers[i].hdLevel[0] : '',
                                        Id: this.HiddenDangers[i].localId,
                                        No: this.HiddenDangers[i].no,
                                        ProblemImgs: this.HiddenDangers[i].problemImgs,
                                        StateDesc: '',
                                        checked: false
                                    })
                                    hasType = true
                                    break
                                }
                            }
                            if (!hasType) {
                                this.listArr2.push({
                                    checkProblemNums: 1,
                                    checkTitleNames: this.HiddenDangers[i].category,
                                    checkTitleNamesId: this.HiddenDangers[i].categoryId,
                                    open: false,
                                    problemSummaries: [
                                        {
                                            Description: this.HiddenDangers[i].description,
                                            HdLevel: this.HiddenDangers[i].hdLevel ? this.HiddenDangers[i].hdLevel[0] : '',
                                            Id: this.HiddenDangers[i].localId,
                                            No: this.HiddenDangers[i].no,
                                            ProblemImgs: this.HiddenDangers[i].problemImgs,
                                            StateDesc: '',
                                            checked: false
                                        }
                                    ]
                                })
                            }
                        }
                    }
                    this.listArr2.forEach(item => {
                        this.total = this.total + item.checkProblemNums
                    })
                }
            }
            )
        },
        // 完成
        btn () {
            if (this.HiddenDangerIds) {
                if (this.$route.query.type == 'HiddenDangerId1') {
                    window.sessionStorage.setItem('HiddenDangerId1', this.HiddenDangerIds)
                }
                if (this.$route.query.type == 'HiddenDangerId2') {
                    window.sessionStorage.setItem('HiddenDangerId2', this.HiddenDangerIds)
                }
                if (this.$route.query.type == 'HiddenDangerId3') {
                    window.sessionStorage.setItem('HiddenDangerId3', this.HiddenDangerIds)
                }
            }
            this.$router.go(-1)
        }
    }
}
</script>
<style lang="less" scope>
.view3Receipt {
    width: 100%;
    height: 100%;
    background-color: #ebeef2;
    .header {
        width: 100%;
        height: 40px;
        line-height: 40px;
        text-align: center;
        position: relative;
        font-size: 18px;
        background: #2269ff;
        color: #fff;
        .vux-x-icon {
            fill: cornsilk;
            position: absolute;
            left: 0;
            top: 5px;
            width: 30px;
            height: 30px;
        }
    }
    .view3ReceiptBox {
        height: 603px;
        width: 100%;
        background-color: #ebeef2;
        h2 {
            height: 50px;
            line-height: 50px;
            padding: 0 10px;
            font-size: 18px;
            background-color: #fff;
            span {
                color: #2269ff;
                float: left;
            }
            em {
                color: #000;
                float: right;
            }
        }
        .affirm-wrap {
            position: fixed;
            z-index: 5;
            bottom: 0;
            left: 0;
            right: 0;
            background: #ebeef2;
        }
        .standard-name span {
            margin-left: 20px;
            font-size: 16px;
        }
        .iconfont {
            margin-left: 20px;
        }
        .item-wrap {
            // padding-left: 20px;
            background: #fff;
            position: relative;
            z-index: 2;
            margin-top: 5px;
        }
        .btn {
            margin: 20px;
            height: 40px;
            div {
                margin: 0 auto;
                width: 204px;
                height: 40px;
                line-height: 40px;
                text-align: center;
                color: #fff;
                background-color: #2269ff;
                border-radius: 20px;
                font-size: 20px;
            }
        }
    }
    .weui-actionsheet {
        top: 30%;
        // width: 90%;
        // left: 20px;
        background-color: rgba(0, 0, 0, 0);
    }
    .weui-actionsheet__menu {
        margin: 0 auto;
        width: 80%;
        height: 200px;
        overflow-y: auto;
        line-height: 20px;
        border-radius: 10px;
    }
    .vux-actionsheet-menu-default {
        padding: 10px !important;
        text-align: left;
    }
}
.pswp {
    display: none;
}
</style>
